package com.se.utils;

import com.se.common.Message;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;

public class ClientMessage {
    private String sendUser;
    private String receiveUser;
    private final SimpleStringProperty content = new SimpleStringProperty();
    private String sendTime;
    private String msgType;
    private final SimpleBooleanProperty isAI = new SimpleBooleanProperty(false);
    private String id;  //仅在消息为AI消息时使用
    private final SimpleIntegerProperty currentDisplayIndex = new SimpleIntegerProperty(0);
    //仅在消息为AI消息时使用
    private String originContent = "";

    public ClientMessage(Message message) {
        this.sendUser = message.getSendUser();
        this.receiveUser = message.getReceiveUser();
        this.content.set(message.getContent());
        this.sendTime = message.getSendTime();
        this.msgType = message.getMsgType();
        this.isAI.set(message.isAI());
        this.id = message.getId();
        this.currentDisplayIndex.set(message.getCurrentDisplayIndex());
    }

    public ClientMessage() {
    }

    public void setClientMessage(Message message) {
        this.sendUser = message.getSendUser();
        this.receiveUser = message.getReceiveUser();
        this.content.set("");
        this.originContent = message.getContent();
        this.sendTime = message.getSendTime();
        this.msgType = message.getMsgType();
        this.isAI.set(message.isAI());
        this.id = message.getId();
        this.currentDisplayIndex.set(message.getCurrentDisplayIndex());
    }

    public String getOriginContent() {
        return originContent;
    }

    public void setOriginContent(String originContent) {
        this.originContent = originContent;
    }

    public SimpleStringProperty getContentProperty() {
        return content;
    }

    public SimpleBooleanProperty getAIProperty() {
        return isAI;
    }

    public String getContent() {
        return content.get();
    }

    public boolean isAI() {
        return isAI.get();
    }

    public void updateContent(String str) {
        content.set(content.get() + str);
    }

    public void setIsAI(boolean bool) {
        isAI.set(bool);
    }

    public String getSendUser() {
        return sendUser;
    }

    public String getReceiveUser() {
        return receiveUser;
    }

    public String getSendTime() {
        return sendTime;
    }

    public String getMsgType() {
        return msgType;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getCurrentDisplayIndex() {
        return currentDisplayIndex.get();
    }

    public SimpleBooleanProperty isCompleteProperty() {
        SimpleBooleanProperty isComplete = new SimpleBooleanProperty();
        isComplete.set(getCurrentDisplayIndex() + 1 == getOriginContent().length());
        return isComplete;
    }

    public void setComplete() {
        setCurrentDisplayIndex(getOriginContent().length() - 1);
    }

    public void setCurrentDisplayIndex(int index) {
        currentDisplayIndex.set(index);
    }

    public SimpleIntegerProperty getCurrentDisplayIndexProperty() {
        return currentDisplayIndex;
    }
}
